package com.pixeljet.activityninja.client;

import java.util.Date;
import java.util.Map;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.gwt.core.client.GWT;
import com.google.gwt.place.shared.Place;


@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class PlaceMovement {
	
	private String name;
	private Date date;
	private Map<String, String> properties;
	
	public PlaceMovement(Place place) {
		this.date = new Date();
		try {
			if(place instanceof SimplePlace) {
				SimplePlace simplePlace = (SimplePlace) place;
				this.name = simplePlace.getName();
			} else if (place instanceof ComplexPlace) {
				ComplexPlace complexPlace = (ComplexPlace) place;
				this.name = complexPlace.getName();
				this.properties = complexPlace.getProperties();
			} else {
				throw new Exception("Your place class needs to implement either SimplePlace or ComplexPlace");
			}
		} catch (Exception e) {
			GWT.log("Your place class has an unexpected incompatibility.");
		}
	}

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
}
